package org.gitos.cloud.comet.logic;

import org.gitos.cloud.comet.logic.recTcpLogic.PushToServerHandler;
import org.gitos.cloud.domain.mq.MqMsg;
import org.gitos.cloud.domain.tcp.Bucket;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Created by szc on 2016/3/19.
 */
@Component
public class InitContextHandler {

    @Autowired
    PushToServerHandler pushToServerHandler;

    private void initPipline(ContextPipline pip){
        pip.lastAdd(pushToServerHandler);
    }

    public ContextLogicHandler tcpHandler(Bucket bucket) {
        ContextPipline pipline = new ContextPipline(bucket, null);
        initPipline(pipline);
        return pipline.getTailHander();
    }

    public ContextLogicHandler mqHandler(MqMsg mqMsg) {
        ContextPipline pipline = new ContextPipline(null, mqMsg);
        initPipline(pipline);
        return pipline.getHeadHander();
    }
}
